//
//  ViewController.m
//  APPTwo
//
//  Created by sun on 2017/9/17.
//  Copyright © 2017年 sun. All rights reserved.
//

#import "ViewController.h"
#import "SFHFKeychainUtils.h"


static NSString *userName = @"test@qq.com";
static NSString *password = @"987654321";
static NSString *service = @"com.shengpay";

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *label;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (IBAction)save:(id)sender {
    BOOL saved = [SFHFKeychainUtils storeUsername:userName andPassword:password forServiceName:service updateExisting:YES error:nil];
    
    if (saved) {
        NSLog(@"保存成功！");
    } else {
        NSLog(@"保存失败！");
    }
    
}

- (IBAction)fetch:(id)sender {
    
    NSError *error = nil;
    
    self.label.text = [SFHFKeychainUtils getPasswordForUsername:userName andServiceName:service error:&error];
    if (self.label.text.length <= 0) {
        NSLog(@"读取失败！！！");
    }
    
    if (error) {
        NSLog(@"error:%@", error);
    }
    
}
- (IBAction)delete:(id)sender {
    BOOL dele = [SFHFKeychainUtils deleteItemForUsername:userName andServiceName:service error:nil];
    if (dele) {
        NSLog(@"删除成功！！");
    } else {
        NSLog(@"删除失败！！");
    }
    
}
- (IBAction)pergue:(id)sender {
    BOOL isPurge = [SFHFKeychainUtils purgeItemsForServiceName:userName error:nil];
    if (isPurge) {
        NSLog(@"已清空");
    } else {
        NSLog(@"清空失败！！");
    }
}

@end
